Projects

Projects

Projects provide a logical grouping of applications, which is useful when Argo CD is used by multiple teams. Projects provide the following features:

  • restrict what may be deployed (trusted Git source repositories)
  • restrict where apps may be deployed to (destination clusters and namespaces)
  • restrict what kinds of objects may or may not be deployed (e.g. RBAC, CRDs, DaemonSets, NetworkPolicy etc…)
  • defining project roles to provide application RBAC (bound to OIDC groups and/or JWT tokens)

The Default Project

Every application belongs to a single project. If unspecified, an application belongs to the default project, which is created automatically and by default, permits deployments from any source repo, to any cluster, and all resource Kinds. The default project can be modified, but not deleted. When initially created, it’s specification is configured to be the most permissive:

  1. spec:
  2. sourceRepos:
  3. - '*'
  4. destinations:
  5. - namespace: '*'
  6. server: '*'
  7. clusterResourceWhitelist:
  8. - group: '*'
  9. kind: '*'

Creating Projects

Additional projects can be created to give separate teams different levels of access to namespaces. The following command creates a new project myproject which can deploy applications to namespace mynamespace of cluster https://kubernetes.default.svc. The permitted Git source repository is set to https://github.com/argoproj/argocd-example-apps.git repository.

  1. argocd proj create myproject -d https://kubernetes.default.svc,mynamespace -s https://github.com/argoproj/argocd-example-apps.git

Managing Projects

Permitted source Git repositories are managed using commands:

  1. argocd proj add-source <PROJECT> <REPO>
  2. argocd proj remove-source <PROJECT> <REPO>

We can also do negations of sources (i.e. do not use this repo).

  1. argocd proj add-source <PROJECT> !<REPO>
  2. argocd proj remove-source <PROJECT> !<REPO>

Declaratively we can do something like this:

  1. spec:
  2. sourceRepos:
  3. # Do not use the test repo in argoproj
  4. - '!ssh://git@GITHUB.com:argoproj/test'
  5. # Nor any Gitlab repo under group/
  6. - '!https://gitlab.com/group/**'
  7. # Any other repo is fine though
  8. - '*'

A source repository is considered valid if the following conditions hold:

  1. Any allow source rule (i.e. a rule which isn’t prefixed with !) permits the source
  2. AND no deny source (i.e. a rule which is prefixed with !) rejects the source

Keep in mind that !* is an invalid rule, since it doesn’t make any sense to disallow everything.

Permitted destination clusters and namespaces are managed with the commands (for clusters always provide server, the name is not used for matching):

  1. argocd proj add-destination <PROJECT> <CLUSTER>,<NAMESPACE>
  2. argocd proj remove-destination <PROJECT> <CLUSTER>,<NAMESPACE>

As with sources, we can also do negations of destinations (i.e. install anywhere apart from).

  1. argocd proj add-destination <PROJECT> !<CLUSTER>,!<NAMESPACE>
  2. argocd proj remove-destination <PROJECT> !<CLUSTER>,!<NAMESPACE>

Declaratively we can do something like this:

  1. spec:
  2. destinations:
  3. # Do not allow any app to be installed in `kube-system`
  4. - namespace: '!kube-system'
  5. server: '*'
  6. # Or any cluster that has a URL of `team1-*`
  7. - namespace: '*'
  8. server: '!https://team1-*'
  9. # Any other namespace or server is fine though.
  10. - namespace: '*'
  11. server: '*'

As with sources, a destination is considered valid if the following conditions hold:

  1. Any allow destination rule (i.e. a rule which isn’t prefixed with !) permits the destination
  2. AND no deny destination (i.e. a rule which is prefixed with !) rejects the destination

Keep in mind that !* is an invalid rule, since it doesn’t make any sense to disallow everything.

Permitted destination K8s resource kinds are managed with the commands. Note that namespaced-scoped resources are restricted via a deny list, whereas cluster-scoped resources are restricted via allow list.

  1. argocd proj allow-cluster-resource <PROJECT> <GROUP> <KIND>
  2. argocd proj allow-namespace-resource <PROJECT> <GROUP> <KIND>
  3. argocd proj deny-cluster-resource <PROJECT> <GROUP> <KIND>
  4. argocd proj deny-namespace-resource <PROJECT> <GROUP> <KIND>

Assign Application To A Project

The application project can be changed using app set command. In order to change the project of an app, the user must have permissions to access the new project.

  1. argocd app set guestbook-default --project myproject

Project Roles

Projects include a feature called roles that enable automated access to a project’s applications. These can be used to give a CI pipeline a restricted set of permissions. For example, a CI system may only be able to sync a single app (but not change its source or destination).

Projects can have multiple roles, and those roles can have different access granted to them. These permissions are called policies, and they are stored within the role as a list of policy strings. A role’s policy can only grant access to that role and are limited to applications within the role’s project. However, the policies have an option for granting wildcard access to any application within a project.

In order to create roles in a project and add policies to a role, a user will need permission to update a project. The following commands can be used to manage a role.

  1. argocd proj role list
  2. argocd proj role get
  3. argocd proj role create
  4. argocd proj role delete
  5. argocd proj role add-policy
  6. argocd proj role remove-policy

Project roles in itself are not useful without generating a token to associate to that role. Argo CD supports JWT tokens as the means to authenticate to a role. Since the JWT token is associated with a role’s policies, any changes to the role’s policies will immediately take effect for that JWT token.

The following commands are used to manage the JWT tokens.

  1. argocd proj role create-token PROJECT ROLE-NAME
  2. argocd proj role delete-token PROJECT ROLE-NAME ISSUED-AT

Since the JWT tokens aren’t stored in Argo CD, they can only be retrieved when they are created. A user can leverage them in the cli by either passing them in using the --auth-token flag or setting the ARGOCD_AUTH_TOKEN environment variable. The JWT tokens can be used until they expire or are revoked. The JWT tokens can created with or without an expiration, but the default on the cli is creates them without an expirations date. Even if a token has not expired, it cannot be used if the token has been revoked.

Below is an example of leveraging a JWT token to access a guestbook application. It makes the assumption that the user already has a project named myproject and an application called guestbook-default.

  1. PROJ=myproject
  2. APP=guestbook-default
  3. ROLE=get-role
  4. argocd proj role create $PROJ $ROLE
  5. argocd proj role create-token $PROJ $ROLE -e 10m
  6. JWT=<value from command above>
  7. argocd proj role list $PROJ
  8. argocd proj role get $PROJ $ROLE
  9. # This command will fail because the JWT Token associated with the project role does not have a policy to allow access to the application
  10. argocd app get $APP --auth-token $JWT
  11. # Adding a policy to grant access to the application for the new role
  12. argocd proj role add-policy $PROJ $ROLE --action get --permission allow --object $APP
  13. argocd app get $APP --auth-token $JWT
  14. # Removing the policy we added and adding one with a wildcard.
  15. argocd proj role remove-policy $PROJ $ROLE -a get -o $APP
  16. argocd proj role add-policy $PROJ $ROLE -a get --permission allow -o '*'
  17. # The wildcard allows us to access the application due to the wildcard.
  18. argocd app get $APP --auth-token $JWT
  19. argocd proj role get $PROJ $ROLE
  20. argocd proj role get $PROJ $ROLE
  21. # Revoking the JWT token
  22. argocd proj role delete-token $PROJ $ROLE <id field from the last command>
  23. # This will fail since the JWT Token was deleted for the project role.
  24. argocd app get $APP --auth-token $JWT

Configuring RBAC With Projects

The project Roles allows configuring RBAC rules scoped to the project. The following sample project provides read-only permissions on project applications to any member of my-oidc-group group.

AppProject example:

  1. apiVersion: argoproj.io/v1alpha1
  2. kind: AppProject
  3. metadata:
  4. name: my-project
  5. namespace: argocd
  6. spec:
  7. roles:
  8. # A role which provides read-only access to all applications in the project
  9. - name: read-only
  10. description: Read-only privileges to my-project
  11. policies:
  12. - p, proj:my-project:read-only, applications, get, my-project/*, allow
  13. groups:
  14. - my-oidc-group

You can use argocd proj role CLI commands or project details page in the user interface to configure the policy. Note that each project role policy rule must be scoped to that project only. Use the argocd-rbac-cm ConfigMap described in RBAC documentation if you want to configure cross project RBAC rules.

Configuring Global Projects (v1.8)

Global projects can be configured to provide configurations that other projects can inherit from.

Projects, which match matchExpressions specified in argocd-cm ConfigMap, inherit the following fields from the global project:

  • namespaceResourceBlacklist
  • namespaceResourceWhitelist
  • clusterResourceBlacklist
  • clusterResourceWhitelist
  • SyncWindows
  • SourceRepos
  • Destinations

Configure global projects in argocd-cm ConfigMap:

  1. data:
  2. globalProjects: |-
  3. - labelSelector:
  4. matchExpressions:
  5. - key: opt
  6. operator: In
  7. values:
  8. - prod
  9. projectName: proj-global-test
  10. kind: ConfigMap

Valid operators you can use are: In, NotIn, Exists, DoesNotExist. Gt, and Lt.

projectName: proj-global-test should be replaced with your own global project name.

Project scoped Repositories and Clusters

Normally, an Argo CD admin creates a project and decides in advance which clusters and Git repositories it defines. However, this creates a problem in scenarios where a developer wants to add a repository or cluster after the initial creation of the project. This forces the developer to contact their Argo CD admin again to update the project definition.

It is possible to offer a self-service process for developers so that they can add a repository and/or cluster in a project on their own even after the initial creation of the project.

For this purpose Argo CD supports project-scoped repositories and clusters.

To begin the process, Argo CD admins must configure RBAC security to allow this self-service behavior. For example, to allow users to add project scoped repositories and admin would have to add the following RBAC rules:

  1. p, proj:my-project:admin, repositories, create, my-project/*, allow
  2. p, proj:my-project:admin, repositories, delete, my-project/*, allow
  3. p, proj:my-project:admin, repositories, update, my-project/*, allow

This provides extra flexibility so that admins can have stricter rules. e.g.:

  1. p, proj:my-project:admin, repositories, update, my-project/https://github.my-company.com/*, allow

Once the appropriate RBAC rules are in place, developers can create their own Git repositories and (assuming they have the correct credentials) can add them in an existing project either from the UI or the CLI. Both the User interface and the CLI have the ability to optionally specify a project. If a project is specified then the respective cluster/repository is considered project scoped:

argocd repo add --name stable https://charts.helm.sh/stable --type helm --project my-project

For the declarative setup both repositories and clusters are stored as Kubernetes Secrets, and so a new field is used to denote that this resource is project scoped:

  1. apiVersion: v1
  2. kind: Secret
  3. metadata:
  4. name: argocd-example-apps
  5. labels:
  6. argocd.argoproj.io/secret-type: repository
  7. type: Opaque
  8. stringData:
  9. project: my-project1 # Project scoped
  10. name: argocd-example-apps
  11. url: https://github.com/argoproj/argocd-example-apps.git
  12. username: ****
  13. password: ****

All the examples above talk about Git repositories, but the same principles apply to clusters as well.

With project-scoped clusters we can also restrict projects to only allow applications whose destinations belong to the same project. The default behavior allows for applications to be installed onto clusters which are not a part of the same project, as the example below demonstrates:

  1. apiVersion: argoproj.io/v1alpha1
  2. kind: Application
  3. metadata:
  4. name: "some-ns"
  5. spec:
  6. destination:
  7. # This destination might not actually be a cluster which belongs to `foo-project`
  8. server: https://some-k8s-server/
  9. namespace: "some-ns"
  10. project: foo-project

To prevent this behavior, we can set the attribute permitOnlyProjectScopedClusters on a project.

  1. spec:
  2. permitOnlyProjectScopedClusters: true

With this set, the application above would no longer be allowed to be synced to any cluster other than the ones which are a part of the same project.